<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/design/template.xhtml">
  <ui:define name="body">
  <h:form id="frmOrder" prependId="false" >
    <h:inputHidden id="orderId" value="#{orderAction.order.id}" /> 
    <p:panel id="pnlOrder" header="Dados pedido">

      <p:messages/>
      <h:panelGrid columns="3" >
        <h:outputText value="Data pedido:" />
        <p:spacer width="8" />
        <p:inputMask value="#{orderAction.order.orderDate}" mask="99/99/9999" disabled="true" inputStyle="width:120px;" 
                     rendered="#{orderAction.actionEdit}">
          <f:convertDateTime pattern="dd/MM/yyyy" />
        </p:inputMask>
        <p:calendar id="orderDate" value="#{orderAction.order.orderDate}" pattern="dd/MM/yyyy" inputStyle="width:120px;"
                    required="true" mode="popup" showOn="button" popupIconOnly="true" readOnlyInputText="true"
                    requiredMessage="Data pedido obrigatoria!" 
                    validatorMessage="Data pedido inválida!"  
                    converterMessage="Data pedido inválida!" 
                    rendered="#{orderAction.actionInsert}" />  
        <h:outputText value="Fornecedor:" />
        <p:spacer width="8" />
        <h:selectOneMenu id="sellerId" value="#{orderAction.order.seller.id}" style="width:150px;" 
                         required="true" requiredMessage="Fornecedor obrigatorio!">  
          <f:selectItem itemValue="" itemLabel="Selecione um tipo"/>  
          <f:selectItems value="#{orderAction.sellerItems}"/>  
        </h:selectOneMenu>
        <h:outputText value="Produto:" />
        <p:spacer width="8" />
        <h:selectOneMenu id="productId" value="#{orderAction.order.product.id}" style="width:150px;" 
                         required="true" requiredMessage="Produto obrigatorio">  
          <f:selectItem itemValue="" itemLabel="Selecione um tipo"/>  
          <f:selectItems value="#{orderAction.productItems}"/>  
        </h:selectOneMenu>
        <h:outputText value="Número pedido:" />
        <p:spacer width="8" />
        <p:inputText id="sellerOrderId" value="#{orderAction.order.sellerOrderId}" style="width:200px;" ></p:inputText>
        <h:outputText value="Número rastreamento:" />
        <p:spacer width="8" />
        <p:inputText id="shippingId" value="#{orderAction.order.shippingId}" style="width:200px;" ></p:inputText>
        <h:outputText value="Data recebimento:" rendered="#{orderAction.order.status.received || orderAction.order.status.sold}" />
        <p:spacer width="8" rendered="#{orderAction.order.status.received || orderAction.order.status.sold}" />
        <p:calendar id="arriveDate" value="#{orderAction.order.arriveDate}" pattern="dd/MM/yyyy" inputStyle="width:120px;"
                    required="true" mode="popup" showOn="button" popupIconOnly="true" readOnlyInputText="true"
                    requiredMessage="Data venda obrigatoria!" 
                    validatorMessage="Data venda inválida!"  
                    converterMessage="Data venda inválida!"  
                    rendered="#{orderAction.order.status.received || orderAction.order.status.sold}" />
        <h:outputText value="Data pagamento:" rendered="#{orderAction.order.paymentStatus.payed}" />
        <p:spacer width="8" rendered="#{orderAction.order.paymentStatus.payed}" />
        <p:calendar id="paymentDate" value="#{orderAction.order.paymentDate}" pattern="dd/MM/yyyy" inputStyle="width:120px;"
                    required="true" mode="popup" showOn="button" popupIconOnly="true" readOnlyInputText="true"
                    requiredMessage="Data pagamento obrigatoria!" 
                    validatorMessage="Data pagamento inválida!"  
                    converterMessage="Data pagamento inválida!"  
                    rendered="#{orderAction.order.paymentStatus.payed}" />
        <h:outputText value="Data venda:" rendered="#{orderAction.order.status.sold}" />
        <p:spacer width="8" rendered="#{orderAction.order.status.sold}" />
        <p:calendar id="sellDate" value="#{orderAction.order.sellDate}" pattern="dd/MM/yyyy" inputStyle="width:120px;"
                    required="true" mode="popup" showOn="button" popupIconOnly="true" readOnlyInputText="true"
                    requiredMessage="Data venda obrigatoria!" 
                    validatorMessage="Data venda inválida!"  
                    converterMessage="Data venda inválida!"  
                    rendered="#{orderAction.order.status.sold}" />
        <h:outputText value="Moeda:" />
        <p:spacer width="8" />
        <h:panelGroup>
          <h:selectBooleanCheckbox id="currencyType" value="#{orderAction.order.dollar}"></h:selectBooleanCheckbox><h:outputText value="Dolar" />
        </h:panelGroup>
        <h:outputText value="Cotação moeda:" rendered="#{orderAction.order.paymentStatus.payed and orderAction.order.dollar}" />
        <p:spacer width="8" rendered="#{orderAction.order.paymentStatus.payed and orderAction.order.dollar}" />
        <p:inputText id="currencyValue" value="#{orderAction.order.currencyValue}" 
                     required="true" requiredMessage="Valor obrigatorio!" 
                     converterMessage="Valor cotação inválido"
                     validatorMessage="Valor cotação inválido"
                     onkeyup="formataValor(this,'.',',')" 
                     rendered="#{orderAction.order.paymentStatus.payed and orderAction.order.dollar}" >
                     <p:ajax update="totalDollarValue, totalRealValue" />                     
                     <f:validateDoubleRange minimum="0.01" />
                     <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
        </p:inputText>  
        <h:outputText value="Valor:" />
        <p:spacer width="8" />
        <p:inputText id="buyValue" value="#{orderAction.order.buyValue}"
                     required="true" requiredMessage="Valor obrigatorio!" 
                     converterMessage="Valor produto inválido"
                     validatorMessage="Valor produto inválido"
                     onkeyup="formataValor(this,'.',',')" >
                     <p:ajax update="totalDollarValue, totalRealValue" />                     
                     <f:validateDoubleRange minimum="0.01" />
                     <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
        </p:inputText>  
        <h:outputText value="Frete:" />
        <p:spacer width="8" />
        <p:inputText id="shippingValue" value="#{orderAction.order.shippingValue}" 
                     converterMessage="Valor frete inválido"
                     validatorMessage="Valor frete inválido" 
                     onkeyup="formataValor(this,'.',',')" >
                     <p:ajax update="totalDollarValue, totalRealValue" />                     
                     <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
        </p:inputText>  
        <h:outputText value="Taxa:" rendered="#{orderAction.order.paymentStatus.payed}" />
        <p:spacer width="8" rendered="#{orderAction.order.paymentStatus.payed}" />
        <p:inputText id="taxValue" value="#{orderAction.order.taxValue}" 
                     converterMessage="Valor frete inválido"
                     validatorMessage="Valor frete inválido" 
                     onkeyup="formataValor(this,'.',',')" 
                     rendered="#{orderAction.order.paymentStatus.payed}" >
                     <p:ajax update="totalDollarValue, totalRealValue" />                     
                     <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
        </p:inputText>
        <h:outputText value="Venda:" rendered="#{orderAction.order.status.sold}" />
        <p:spacer width="8" rendered="#{orderAction.order.status.sold}" />
        <p:inputText id="sellValue" value="#{orderAction.order.sellValue}" 
                     converterMessage="Valor frete inválido"
                     validatorMessage="Valor frete inválido" 
                     onkeyup="formataValor(this,'.',',')" 
                     rendered="#{orderAction.order.status.sold}" >
                     <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
        </p:inputText>
        <h:outputText value="Total U$" rendered="#{orderAction.order.paymentStatus.payed and orderAction.order.dollar}" />
        <p:spacer width="8" rendered="#{orderAction.order.paymentStatus.payed and orderAction.order.dollar}" />
        <p:inputText id="totalDollarValue" value="#{orderAction.order.totalDollarBuyValue}" readonly="true" 
                     rendered="#{orderAction.order.paymentStatus.payed and orderAction.order.dollar}" >
                     <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
        </p:inputText>
        <h:outputText value="Total R$" rendered="#{orderAction.order.paymentStatus.payed}" />
        <p:spacer width="8" rendered="#{orderAction.order.paymentStatus.payed}" />
        <p:inputText id="totalRealValue" value="#{orderAction.order.totalBuyValue}" readonly="true" 
                     rendered="#{orderAction.order.paymentStatus.payed}" >
                     <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
        </p:inputText>
      </h:panelGrid>

      <p:spacer height="10" />
      <p:outputPanel id="pnlButons">
        <div align="left" id="divButons">
          <p:commandButton action="#{orderAction.listOrders}" value="cancelar" update="pnlOrder" ajax="false" immediate="true" />
          <p:spacer width="10" />
          <p:commandButton action="#{orderAction.editOrder}" value="alterar" update="pnlOrder" ajax="false" rendered="#{orderAction.actionEdit}" />
          <p:commandButton action="#{orderAction.insertOrder}" value="incluir" update="pnlOrder" ajax="false" rendered="#{orderAction.actionInsert}" />
        </div>
      </p:outputPanel>			

    </p:panel>
  </h:form>

  </ui:define>
</ui:composition>
